const tokens = {
    admin: {
        token: 'admin-token'
    },
    editor: {
        token: 'editor-token'
    }
}

const usersInfo = {
    'admin-token': {
        roles: ['admin'],
        introduction: 'I am a super administrator',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: 'Super Admin'
    },
    'editor-token': {
        roles: ['editor'],
        introduction: 'I am an editor',
        avatar: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=673480779,955216698&fm=26&gp=0.jpg',
        name: 'Normal Editor'
    }
}

module.exports = [
    // login 
    {
        url: '/vue-test-template/user/login',
        type: 'post',
        response: config => {
            const { username } = config.body
            const token = tokens[username]
            if (!token) {
                return {
                    code: 30200,
                    message: '用户名或密码错误'
                }
            }
            return {
                code: 20000,
                data: token
            }
        }
    },

    // get userInfo
    {
        url: '/vue-test-template/user/getInfo',
        type: 'get',
        response: config => {
            const { token } = config.query
            const info = usersInfo[token]

            if (!info) {
                return {
                    code: 60200,
                    message: '登录失败，暂无用户信息.'
                }
            }
            return {
                code: 20000,
                data: info
            }
        }
    },


    // logout
    {
        url: '/vue-admin-template/user/logout',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    }
]